package com.niuxiaofa.newlaw.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.niuxiaofa.newlaw.Bean.ByUserBean;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.UUDateUtils;
import com.niuxiaofa.newlaw.View.CollapsibleTextView;
import com.niuxiaofa.newlaw.View.NineGridTestLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class DynamicAdapter extends RecyclerView.Adapter<DynamicAdapter.ViewHolder> {
    public List<ByUserBean.DataDTO> listEntities;
    Onclick onclick;

    List<String> list = new ArrayList<>();

    public DynamicAdapter(List<ByUserBean.DataDTO> newsList, Onclick onclick) {
        this.onclick = onclick;
        this.listEntities = newsList;
    }

    
    @Override
    public ViewHolder onCreateViewHolder( ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_dybamic, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }


    @Override
    public void onBindViewHolder( ViewHolder viewHolder, int i) {
        ByUserBean.DataDTO dataDTO = listEntities.get(i);

        viewHolder.name.setText(dataDTO.getUsername());
        viewHolder.time.setText(UUDateUtils.interceptTime(dataDTO.getCreateTime()));
        viewHolder.collapsibleTextView.setText("2313");
        viewHolder.nineGridTestLayout.setUrlList(list);

    }

    @Override
    public int getItemCount() {
        return listEntities.size();
    }

    public interface Onclick {

        void onclick(int c);

    }

    static class ViewHolder extends RecyclerView.ViewHolder {


        @BindView(R.id.user_name)
        TextView name;

        @BindView(R.id.user_img)
        ImageView user_img;

        @BindView(R.id.time)
        TextView time;

        @BindView(R.id.like)
        ImageView like;


        @BindView(R.id.collapsibletext)
        CollapsibleTextView collapsibleTextView;


        @BindView(R.id.nine_grid)
        NineGridTestLayout nineGridTestLayout;

        public ViewHolder( View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
